﻿using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;

namespace Wenyu.Framework.WebCore.CorsExtend
{
    public static class CorsExtension
    {
        /// <summary>
        /// 配置跨域
        /// </summary>
        /// <param name="service"></param>
        public static void AddCorsExt(this IServiceCollection service)
        {
            service.AddCors(options =>
            {
                options.AddPolicy("allCors", policy =>
                {
                    policy.AllowAnyHeader()
                        .AllowAnyOrigin()
                        .AllowAnyMethod();
                });
            });
        }
        /// <summary>
        /// 使用跨域策略生效
        /// </summary>
        /// <param name="app"></param>
        public static void UseCorsExt(this WebApplication app)
        {
            app.UseCors("allCors");
        }
    }
}
